package qdu.rg012.ch1_intent_adv;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import androidx.annotation.Nullable;

public class Act_extras extends Activity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ly_actextra);

        findViewById(R.id.btn_switch).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent it = new Intent(Act_extras.this, Act_receive.class);
                //it.putExtra("msg1", 15);
                //it.putExtra("msg2", "msg from act_extras...");
                Bundle bd = new Bundle();
                bd.putInt("msg3",17);
                bd.putString("msg4","msg in bundle");
                it.putExtras(bd);
                startActivityForResult(it, 456);
            }
        });

        findViewById(R.id.btn_swt2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent it = new Intent(Act_extras.this, Act_return.class);
                //startActivity(it);
                startActivityForResult(it,123);
            }
        });

        //this.getIntent()
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if((requestCode == 123) && (resultCode == 789)){
            Log.i("mytag", String.valueOf(data.getIntExtra("returnmsg", -1)));
        }

    }
}
